﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PozrSvc.Controls
{
    public partial class CtlModuleCfg : UserControl
    {
        public CtlModuleCfg()
        {
            InitializeComponent();
        }

        public void RefreshItems()
        {
            lbModules.Items.Clear();
            foreach (string s in Middleware.PluginServices.ModuleList)
            {
                if (Middleware.PluginServices.GetActiveModules().Contains(s))
                {
                    lbModules.Items.Add("*" + s);
                }
                else
                {
                    lbModules.Items.Add(s);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (lbModules.SelectedIndex >= 0)
            {
                string selectedModule = lbModules.Items[lbModules.SelectedIndex].ToString();
                if (Middleware.PluginServices.GetActiveModules().Contains(selectedModule.TrimStart('*')))
                {
                    Middleware.PluginServices.ClosePlugin(selectedModule.TrimStart('*'));
                }
                else
                {
                    // dummy
                }
            }
            RefreshItems();
        }
    }
}
